﻿using AutoMapper;
using BaseData.API.Write.Applications.HospitalInformation.Command;
using BaseData.Domain.HospitalInformation;
using BaseData.ErrorCode;
using BaseData.Infrastructure.Interfaces;
using MediatR;

namespace BaseData.API.Write.Applications.HospitalInformation.Commandhandler
{
    public class DoctorsAddCommandHandler:IRequestHandler<DoctorsAddCommand,ApiResult<int>>
    {
        IBaseRepository<Doctors> repository;
        IMapper mapper;

        public DoctorsAddCommandHandler(IBaseRepository<Doctors> repository, IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }

        public async Task<ApiResult<int>> Handle(DoctorsAddCommand request, CancellationToken cancellationToken)
        {
            var res = mapper.Map<Doctors>(request);
            await repository.AddAsync(res);
            return new ApiResult<int>()
            {
                Message = ApiEnum.添加成功.ToString(),
                Code = ApiEnum.添加成功,
            };
        }
    }
}
